package prueba4;
import java.awt.*;

import javax.swing.*;

import prueba2.DragPictureDemo;

import java.awt.event.*;
import java.awt.image.BufferedImage;
public class SmoothMoveExample extends JPanel implements
MouseMotionListener {
 private int X, Y;
 private Image image;
 private BufferedImage bi;

public static void main(String[] args) {
   JFrame frame = new JFrame();
   frame.getContentPane().add(new SmoothMoveExample());
   frame.setSize(350, 300);
   frame.show();
 }
 public SmoothMoveExample() {
	 checkImage();
	   bi = new BufferedImage(image.getWidth(this), image.getHeight(this),
		        BufferedImage.TYPE_INT_RGB);
		    Graphics2D big = bi.createGraphics();
		    big.drawImage(image, 0, 0, this);
   addMouseMotionListener(this);
   setVisible(true);
 }
 public void mouseMoved(MouseEvent event) {
    X = (int) event.getPoint().getX();
   Y = (int) event.getPoint().getY();
   repaint();
 }
 public void mouseDragged(MouseEvent event) {
   mouseMoved(event);
 }
 public void update(Graphics graphics) {
   paint(graphics);
 }
 public void paint(Graphics g) {

   

//   Graphics graphics = image.getGraphics();
//   graphics.setColor(getBackground());
//   graphics.fillRect(0, 0, dim.width, dim.height);


   
   super.paintComponent(g);
   Graphics2D g2D = (Graphics2D) g;

   g2D.drawImage(bi, X, Y, this);
 }
 private void checkImage() {
//   Dimension dim = getSize();
//   if (image == null || image.getWidth(null) != dim.width
//       || image.getHeight(null) != dim.height) {
//     image = createImage(dim.width, dim.height);
//   }
	 image = createImageIcon("/Imagenes/img0356.gif").getImage();
 }
 public ImageIcon createImageIcon(String path) {
	    java.net.URL imageURL = DragPictureDemo.class.getResource(path);

	    if (imageURL == null) {
	      System.err.println("Resource not found: " + path);
	      return null;
	    } else {
	      return new ImageIcon(imageURL);
	    }
	  }
 
}